import Taro from '@tarojs/taro'
/**
 * 请求函数
 */
const request = async(url: string, method: any, data?) => {
  const params = {
    // @ts-ignore
    url: baseUrl + url,
    method,
    data,
    header
  }
  const res = await Taro.request(params).catch(error => {
    throw error
  })
  // 状态码400+ 服务器出错
  if (res.statusCode >= 400) throw new Error('request error')
  return res.data
}
// 公共请求头
const header = {
  "Content-Type": "application/json"
}

export default request